package demo1230.homework;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Demo4 {
    public static void main(String[] args) {
        ExecutorService pool = Executors.newFixedThreadPool(3);
        pool.submit(new ru());
        pool.submit(new ru());
        pool.submit(new ru());
        pool.shutdown();
    }

}

class ru implements Runnable {


    private static int tickets = 100;
    private static Lock lock = new ReentrantLock();

    @Override
    public void run() {

        while (tickets > 0) {

            lock.lock();
            if (tickets > 0) {

                System.out.println("正在卖第" + tickets + "张票,还剩" + --tickets + "张票");

            }
            lock.unlock();

        }


    }
}